package com.huluobo.a2208kotlindouyindemo.videos

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.CommentBean
import com.huluobo.base.bean.VideoBean
import com.huluobo.base.db.DouYinDatabase
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/12/25.
 */
@HiltViewModel
class VideoViewModel @Inject constructor(
    val apiService: ApiService,
    val db: DouYinDatabase
) : BaseViewModel() {
    val getVideosSuccess by lazy { MutableLiveData<List<VideoBean>>() }
    fun getVideos(currentPage: Int, pageSize: Int) {
        executeNetwork(
            { apiService.getVideos(currentPage, pageSize) },
            getVideosSuccess::postValue
        )
    }

    val likeVideoSuccess by lazy { MutableLiveData<String>() }
    fun likeVideo(videoId: Int) {
        executeNetwork(
            { apiService.likeVideo(videoId) },
            likeVideoSuccess::postValue
        )
    }

    val noLikeVideoSuccess by lazy { MutableLiveData<String>() }
    fun noLikeVideo(videoId: Int) {
        executeNetwork(
            { apiService.noLikeVideo(videoId) },
            noLikeVideoSuccess::postValue
        )
    }

    val followAuthSuccess by lazy { MutableLiveData<String>() }
    fun followAuth(body: RequestBody) {
        executeNetwork(
            { apiService.followAuth(body) },
            followAuthSuccess::postValue
        )
    }

    val getCommentSuccess by lazy { MutableLiveData<List<CommentBean>>() }
    fun getComment(videoId: Int) {
        executeNetwork(
            { apiService.getComment(videoId) },
            getCommentSuccess::postValue
        )
    }

    val sendCommentSuccess by lazy { MutableLiveData<List<CommentBean>>() }
    fun sendComment(body: RequestBody) {
        executeNetwork(
            { apiService.sendComment(body) },
            sendCommentSuccess::postValue
        )
    }

    val collectVideoSuccess by lazy { MutableLiveData<String>() }
    fun collectVideo(videoBean: VideoBean) {
        executeDb(
            {
                db.getVideoDao().insertVideoInfo(videoBean)
                "收藏成功"
            },
            collectVideoSuccess::postValue
        )
    }
}